package com.crm.jdy.controller.usermanager;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.PermissionInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.PermissionInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.crm.jdy.service.usermanager.PermissionInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 权限管理API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年3月30日
*
*/
@Validated
@Api(tags = "permissionInfo", description = "权限管理")
@RestController
@RequestMapping("/permissionInfo")
public class PermissionInfoController{

    @Reference(version = "${service.version}", check = false)
    PermissionInfoService callAplanInfoService;

    @RateLimit()
    @ApiOperation("权限管理信息")
    @PostMapping("/seletePermissionInfo")
    public ResultVo seletePermissionInfo(@RequestBody PermissionInfoDto callAplanInfoDto){
        PageInfo<PermissionInfo> list = callAplanInfoService.seletePermissionInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新权限管理")
    @PostMapping("/updatPermissionInfo")
    public ResultVo updatePermissionInfo(@ApiParam(value = "callAplanInfoDto", required = true)
                                         @Validated @RequestBody PermissionInfo callAplanInfoDto){
        boolean index = callAplanInfoService.updatePermissionInfo(callAplanInfoDto);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加权限管理")
    @PostMapping("/addPermissionInfo")
    public ResultVo addPermissionInfo(@ApiParam(name = "callAplanInfo", required = false)
                                      @Validated @RequestBody PermissionInfo callAplanInfo){
        boolean list  = callAplanInfoService.addPermissionInfo(callAplanInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除权限管理")
    @DeleteMapping("deletePermissionInfo/{perId}")
    public ResultVo deletePermissionInfo(@NotNull @ApiParam(name = "perId", value = "perId", required = true) @PathVariable String perId){
        boolean b = callAplanInfoService.removePermissionInfo(perId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }

}